package com.example.delicioushunter.view.adapter;

import java.util.ArrayList;

import com.example.delicioushunter.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class MaterialGalleryAdapter extends BaseAdapter {
	int GalItemBg;
	private Context mContext;

	ArrayList<Bitmap> images;

	public MaterialGalleryAdapter(Context mContext, ArrayList<Bitmap> images) {
		this.mContext = mContext;
		this.images = images;
		TypedArray typArray = mContext
				.obtainStyledAttributes(R.styleable.GalleryTheme);
		GalItemBg = typArray.getResourceId(
				R.styleable.GalleryTheme_android_galleryItemBackground, 0);
		typArray.recycle();
	}

	public int getCount() {
		return images.size();
	}

	public Object getItem(int position) {
		return images.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("deprecation")
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imgView = new ImageView(mContext);
		imgView.setImageBitmap(images.get(position));
		imgView.setLayoutParams(new Gallery.LayoutParams(150, 150));
		imgView.setScaleType(ImageView.ScaleType.FIT_XY);
		imgView.setBackgroundResource(GalItemBg);

		return imgView;
	}
}